package com.consult.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.consult.config.dto.AjaxResult;
import com.consult.entity.Visitor;
import com.consult.service.IVisitorService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-06-22
 */
@RestController
@RequestMapping("/visitor")
public class VisitorController {

    @Resource
    private IVisitorService visitorService;

    @PostMapping("/page")
    public AjaxResult getVisitorPage(@RequestBody Page<Visitor> page) {
        page = visitorService.getVisitorPage(page);
        return AjaxResult.success(page);
    }

    @PostMapping("/add")
    public AjaxResult addVisitor(@RequestBody Visitor visitor) {
        visitor.setPassword("123456");
        visitorService.save(visitor);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult updateVisitor(@RequestBody Visitor visitor) {
        visitorService.updateById(visitor);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult deleteVisitor(Long id) {
        visitorService.removeById(id);
        return AjaxResult.success();
    }

}

